﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tao.OpenGl;

namespace RacunarskaGrafikaProjekat.source {
    class CBox : IDrawable{
     
     #region Atributi
        double m_height = 1.0;
        double m_width = 1.0;
        double m_depth = 1.0;
     #endregion Atributi

     #region Properties
        public double Height
        {
          get { return m_height; }
          set { m_height = value; }
        }
        public double Width
        {
          get { return m_width; }
          set { m_width = value; }
        }
        public double Depth
        {
          get { return m_depth; }
          set { m_depth = value; }
        }

        protected int asphaltIndex {
            get;
            set;
        }
     #endregion Properties

     #region Konstruktori
        public CBox()
        {
        }
        public CBox(double width, double height, double depth,int asphaltIndex)
        {
          this.m_width  = width;
          this.m_height = height;
          this.m_depth  = depth;
          this.asphaltIndex=asphaltIndex;
        }
     #endregion Konstruktori

     #region Metode
        public void Draw()
        {
          Gl.glEnable(Gl.GL_TEXTURE_2D);
          Gl.glTexEnvi(Gl.GL_TEXTURE_ENV, Gl.GL_TEXTURE_ENV_MODE, Gl.GL_ADD);
          Gl.glBindTexture(Gl.GL_TEXTURE_2D, asphaltIndex);
          Gl.glBegin(Gl.GL_QUADS);

            // Zadnja

            Gl.glVertex3d(m_width / 2, -m_height / 2, -m_depth / 2);
            Gl.glVertex3d(-m_width / 2, -m_height / 2, -m_depth / 2);
            Gl.glVertex3d(-m_width / 2, m_height / 2, -m_depth / 2);
            Gl.glVertex3d(m_width / 2, m_height / 2, -m_depth / 2);

            // Desna
            Gl.glVertex3d(m_width / 2, -m_height / 2, -m_depth / 2);
            Gl.glVertex3d(m_width / 2, m_height / 2, -m_depth / 2);
            Gl.glVertex3d(m_width / 2, m_height / 2, m_depth / 2);
            Gl.glVertex3d(m_width / 2, -m_height / 2, m_depth / 2);

            // Prednja
            Gl.glVertex3d(m_width / 2, -m_height / 2, m_depth / 2);  
            Gl.glVertex3d(m_width / 2, m_height / 2, m_depth / 2);
            Gl.glVertex3d(-m_width / 2, m_height / 2, m_depth / 2);
            Gl.glVertex3d(-m_width / 2, -m_height / 2, m_depth / 2);


            // Leva
            Gl.glVertex3d(-m_width / 2, -m_height / 2, m_depth / 2);
            Gl.glVertex3d(-m_width / 2, m_height / 2, m_depth / 2);
            Gl.glVertex3d(-m_width / 2, m_height / 2, -m_depth / 2);
            Gl.glVertex3d(-m_width / 2, -m_height / 2, -m_depth / 2);

            // Donja
            Gl.glVertex3d(-m_width / 2, -m_height / 2, -m_depth / 2);
            Gl.glVertex3d(m_width / 2, -m_height / 2, -m_depth / 2);
            Gl.glVertex3d(m_width / 2, -m_height / 2, m_depth / 2);
            Gl.glVertex3d(-m_width / 2, -m_height / 2, m_depth / 2);

            // Gornja
            float factor = 10;
            /*
            Gl.glTexCoord2f(1.0f, 1.0f);
            Gl.glVertex3d(-m_width / 2, m_height / 2, -m_depth / 2);
            Gl.glTexCoord2f(1.0f, 0.0f);
            Gl.glVertex3d(-m_width / 2, m_height / 2, m_depth / 2);
            Gl.glTexCoord2f(0.0f, 0.0f);
            Gl.glVertex3d(m_width / 2, m_height / 2, m_depth / 2);
            Gl.glTexCoord2f(0.0f, 1.0f);
            Gl.glVertex3d(m_width / 2, m_height / 2, -m_depth / 2);
            */
            Gl.glTexCoord2f(1.0f, 1.0f * factor);
            Gl.glVertex3d(-m_width / 2, m_height / 2, -m_depth / 2);
            Gl.glTexCoord2f(1.0f, 0.0f);
            Gl.glVertex3d(-m_width / 2, m_height / 2, m_depth / 2);
            Gl.glTexCoord2f(0.0f, 0.0f);
            Gl.glVertex3d(m_width / 2, m_height / 2, m_depth / 2);
            Gl.glTexCoord2f(0.0f, 1.0f*factor);
            Gl.glVertex3d(m_width / 2, m_height / 2, -m_depth / 2);
          Gl.glEnd();
          Gl.glDisable(Gl.GL_TEXTURE_2D);
          Gl.glTexEnvi(Gl.GL_TEXTURE_ENV, Gl.GL_TEXTURE_ENV_MODE, Gl.GL_MODULATE);
        }

        public void SetSize(double width, double height, double depth)
        {
          m_depth = depth;
          m_height = height;
          m_width = width;

        }
     #endregion Metode
  }
}
